//
//  XNSubTableViewController.m
//  XINNingOA
//
//  Created by samuel on 2021/7/13.
//

#import "XNSubTableViewController.h"
#import "XNNormalTableViewCell.h"
#import "XNTableShowDataModel.h"
#import "XNItemHeadView.h"

@interface XNSubTableViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, weak) UITableView *table;

@end

@implementation XNSubTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
    
    
    UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    [backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backItemClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = backItem;
    
    UITableView *table = [[UITableView alloc] init];
    table.dataSource = self;
    table.delegate = self;
    table.estimatedRowHeight = 100;
    table.separatorStyle = UITableViewCellSeparatorStyleNone;
    table.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
    [self.view addSubview:table];
    self.table = table;
    [table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
}

- (void)backItemClick:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.tableShowModel.showDataArray.count;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    XNTableShowDataModel *dataModel = self.tableShowModel;
    XNItemHeadView *headView = [[XNItemHeadView alloc] initWithTitle:dataModel.title];
    headView.showWarning = dataModel.showWarning;
    headView.warningTitle = dataModel.warningStr;
    headView.totalArray = dataModel.headTitleArray;
    return headView;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    XNNormalTableViewCell *cell = [XNNormalTableViewCell tabelViewCellWithTableView:tableView ForIndexPath:indexPath];
    XNShowItemModel *itemModel = self.tableShowModel.showDataArray[indexPath.row];
    cell.itemModel = itemModel;
    return cell;
}


@end
